<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Cookie;
use think\response\Redirect;
use Illuminate\Support\Facades\DB;
class CheckCookie
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!$request->hasCookie('laravel_cookie') ) {
            $backUrl = $request->path();
            return redirect('/login');
        }
        $member_id = $request->cookie('laravel_cookie');
        $member = DB::table('member')->where('member_id',$member_id)->first();
        $request->member_info = $member;
        $request->member_id = $member->member_id;
        Cookie::queue('laravel_cookie', $member->member_id, 10);
        return  $next($request);
    }
}
